define(function (require, exports) {
  exports.ready = function (hashCode, data, cite) {
    yufp.custom.vue({
      el: cite.el,
      data: function () {
        var _this = this;
        return {
          collapseValue: ['1', '4'],
          collapse2FormDisable: true,
          urls: {
            index: backend.workflowService + '/api/bench/todo',
            instanceInfo: backend.workflowService + '/api/core/instanceInfo',
            saveComment: backend.workflowService + '/api/core/saveComment/',
            signIn: backend.workflowService + '/api/core/signIn/',
            unSignIn: backend.workflowService + '/api/core/unSignIn/',
            getComments: backend.workflowService + '/api/core/getAllComments/',
            getNextNodeInfos: backend.workflowService + '/api/core/getNextNodeInfos/',
            submit: backend.workflowService + '/api/core/submit',
            returnBack: backend.workflowService + '/api/core/returnBack',
            refuse: backend.workflowService + '/api/core/refuse',
            callBack: backend.workflowService + '/api/core/callBack',
            jump: backend.workflowService + '/api/core/jump',
            assist: backend.workflowService + '/api/core/assist',
            change: backend.workflowService + '/api/core/change',
            getchangeUser: backend.workflowService + '/api/core/getChangeUsers',
            getassistUser: backend.workflowService + '/api/core/getAssistUsers',
            unSignInTaskPool: backend.workflowService + '/api/core/unsignTaskPool',
            subFlowStart: backend.workflowService + '/api/core/subFlowStart',
            nwfbiz: backend.workflowService + '/api/biz/',
            getCopyUser: backend.workflowService + '/api/core/getCopyUsers'
          },
          height: yufp.frame.size().height - 103,
          currentOrgId: yufp.session.org.id,
          currentUserId: yufp.session.user.userCode,
          returnBackFuncId: '',
          returnBackRootId: '',
          instanceIdInfo: {
            instanceId: '',
            mainInstanceId: '',
            flowName: '',
            flowId: '',
            flowStarter: '',
            flowStarterName: '',
            startTime: '',
            systemId: '',
            orgId: '',
            flowState: '',
            bizId: '',
            bizUserName: '',
            bizUserId: '',
            bizType: '',
            lastNodeId: '',
            lastNodeName: '',
            nodeId: '',
            nodeSign: '',
            nodeName: '',
            nodeState: '',
            nodeStateName: '',
            nodeType: '',
            handleType: '',
            opType: {}
          },
          commentInfo: {
            instanceId: '',
            nodeId: '',
            userId: '',
            commentId: '',
            commentSign: 'O-12',
            userComment: '',
            ext: '无'
          },
          flowParam: [],
          commentRules: {
            userComment: [{
              required: true,
              message: '请填写意见',
              trigger: 'blur'
            }]
          },
          opNames: [ // 操作权限常量列表
            {
              key: 'submit',
              label: '同意',
              value: 'O-12'
            },
            {
              key: 'takeBack',
              label: '拿回',
              value: 'O-0'
            },
            {
              key: 'callBack',
              label: '打回',
              value: 'O-1'
            },
            {
              key: 'returnBack',
              label: '退回',
              value: 'O-2'
            },
            {
              key: 'hangUp',
              label: '挂起',
              value: 'O-3'
            },
            {
              key: 'wakeUp',
              label: '唤醒',
              value: 'O-4'
            },
            {
              key: 'urge',
              label: '催办',
              value: 'O-5'
            },
            {
              key: 'change',
              label: '转办',
              value: 'O-6'
            },
            {
              key: 'assist',
              label: '协办',
              value: 'O-7'
            },
            {
              key: 'refuse',
              label: '否决',
              value: 'O-8'
            },
            {
              key: 'jump',
              label: '跳转',
              value: 'O-9'
            },
            {
              key: 'entrust',
              label: '委托',
              value: 'O-10'
            },
            {
              key: 'copy',
              label: '抄送',
              value: 'O-11'
            },
            {
              key: 'auto',
              label: '自动提交',
              value: 'O-13'
            },
            {
              key: 'end',
              label: '正常结束',
              value: 'O-14'
            },
            {
              key: 'takeBackFirst',
              label: '撤回',
              value: 'O-15'
            },
            {
              key: 'start',
              label: '待发起',
              value: 'O-16'
            }
          ],
          button: { // 按钮权限控制
            submit: '1',
            gather: '0',
            callBack: '0',
            entrust: '0',
            copy: '0',
            jump: '0',
            returnBack: '0',
            change: '0',
            unSignIn: '0',
            signIn: '0',
            assist: '0',
            refuse: '0',
            taskPoolId: '0',
            subFlowId: '0',
            subFlow: ''
          },
          agreeNodeSelect: {
            title: '同意提交',
            showDialog: false,
            nodeUrl: backend.workflowService + '/api/core/getNextNodeInfos/',
            userTitle: '办理人员选择',
            showUserDialog: false,
            userUrl: backend.workflowService + '/api/core/getNodeUsers',
            userTableData: []
          },
          callbackNodeSelect: {
            title: '打回节点选择',
            showDialog: false,
            nodeUrl: backend.workflowService + '/api/core/getCallBackNodes'
          },
          jumpNodeSelect: {
            title: '跳转节点选择',
            showDialog: false,
            nodeUrl: backend.workflowService + '/api/core/getJumpNodes',
            userTitle: '跳转节点办理人员选择'
          },
          UserSelect: {
            jump: '跳转节点办理人员选择',
            assist: '协办人员选择',
            change: '转办人员选择',
            copy: '抄送人员选择',
            showUserDialog: false,
            userUrl: backend.workflowService + '/api/core/getNodeUsers',
            Users: [],
            SelectUsers: []
          },
          biztableColumns: [{
            label: '业务类型',
            prop: 'bizType',
            resizable: true,
            align: 'center'
          },
          {
            label: '描述',
            prop: 'ext',
            resizable: true,
            align: 'center'
          },
          {
            label: '流程名称',
            prop: 'flowName',
            resizable: true,
            align: 'center'
          }
          ],
          jumpNodeModel: '',
          jumpNodes: [],
          input: '',
          title: '',
          index: 0,
          agreeIndex: 0,
          agreeNextNodes: [{}],
          agreeShowRadio: false,
          agreeRadio: '',
          agreeCheckBox: [],
          agreeIsLastRadio: 'N',
          backActiveName: 'first',
          backNodeModel: '',
          userModel: '',
          // usersList: [],
          backNodes: [],
          historyValue: [],
          nodeHistory: [],
          pagesize: 10,
          currpage: 1,
          backnode: 1,
          gatherHandleId: 'gatherHandleId',
          nwfbiztypePage: 'nwfbiztypePage',
          endNodeId: '',
          showbizTypeDialog: false,
          bizTypeTitle: '业务类型选取',
          bizTypeParam: {},
          isCopy: '1',
          copyUserName: '',
          commentinfo: '',
		  bizPage: ''
        };
      },
      mounted: function () { // 进入初始化
        this.instanceInfoFn(data);
        this.instanceIdInfo.instanceId = data.instanceId;
        this.instanceIdInfo.nodeId = data.nodeId;
        this.returnBackFuncId = data.returnBackFuncId;
        this.returnBackRootId = data.returnBackRootId;
        this.currentUserId = data.userId;
      },
      methods: {
        // 详情页Tab页点击事件
        tabClick: function (tab, event) {
          var _this = this;
          if (tab.name == 'second') { // 获取流程历史数据
            yufp.service.request({
              method: 'GET',
              url: _this.urls.getComments,
              data: {
                mainInstanceId: _this.instanceIdInfo.mainInstanceId
              },
              callback: function (code, message, response) {
                if (response.code == 0) {
                  if (response.data != null ? response.data.length > 0 : false) {
                    _this.commentinfo = '';
                    var nodeHistory = response.data;
                    // commentSign翻译
                    for (var i = 0, length = nodeHistory.length; i < length; i++) {
                      nodeHistory[i].commentSign = yufp.lookup.convertKey('OP_TYPE', nodeHistory[i].commentSign);
                      // 时间格式化
                      // nodeHistory[i].startTime = yufp.util.dateFormat(nodeHistory[i].startTime, '{y}-{m}-{d}');
                    }
                    _this.nodeHistory = nodeHistory;
                  } else {
                    _this.commentinfo = '暂无审批历史数据';
                  }
                }
              }
            });
          } else if (tab.name == '4') { // 获取会办信息和页面
            var params = {
              instanceId: _this.instanceIdInfo.instanceId
            };
            if (_this.button['gather'] != '0') {
              _this.$nextTick(function () {
                try {
                  yufp.router.to('gatherHandlePage', params, _this.gatherHandleId);
                } catch (e) {}
              });
            }
          }
        },
        instanceInfoFn: function (param) { // 初始化实例信息
          var _this = this;
          yufp.service.request({
            method: 'GET',
            url: _this.urls.instanceInfo,
            data: param,
            callback: function (code, message, response) {
              if (response.code == 0) {
                _this.instanceIdInfo = response.data;
                if (response.data.comment != null) { // 设置评论反显
                  _this.commentInfo = response.data.comment;
                }
                _this.commentInfo.instanceId = _this.instanceIdInfo.instanceId;
                _this.commentInfo.nodeId = _this.instanceIdInfo.nodeId;
                _this.commentInfo.userId = _this.currentUserId;
                // 按钮权限
                if (response.data.opType != null) {
                  for (var key in _this.button) {
                    var value = response.data.opType[key];
                    if (value != null && value != '') {
                      _this.button[key] = value;
                    }
                  }
                }
                if (response.data.param != null) { // 流程参数初始化
                  for (var key in response.data.param) {
                    var paramTT = {};
                    paramTT.key = key;
                    paramTT.value = response.data.param[key];
                    _this.flowParam.push(paramTT);
                  }
                }
                var nodestate = _this.instanceIdInfo.nodeState;
                if (nodestate != '') { // 翻译节点状态
                  _this.instanceIdInfo.nodeStateName = yufp.lookup.convertKey('OP_TYPE', nodestate);
                }
                var bizPage = _this.instanceIdInfo.bizPage;
                _this.bizPage = _this.instanceIdInfo.bizPage;
                if (bizPage.includes('?')) {
                  var str = bizPage.split('?');
                  bizPage = str[0];
                  _this.bizPage = str[0];
                  _this.convertParam(str[1]);
                }
                var paramT = {
                  instanceInfo: _this.instanceIdInfo,
                  flowParam: _this.flowParam
                };
                _this.$nextTick(function () {
                  try {
				      yufp.router.to(bizPage, paramT, _this.nwfbiztypePage);
                  } catch (e) {}
                });
              } else {
                _this.$message({ duration: 6000,
                  duration: '10',
                  message: '获取实例信息异常:' + response.message.substring(0, 100),
                  type: 'error'
                });
              }
            }
          });
        },
        convertParam: function (params) {
          if (params.includes(',')) {
            params = params.split(',');
            for (var k = 0; k < params.length; k++) {
              var paramf = {};
              var item = params[k];
              paramf.key = item.split('=')[0];
              paramf.value = item.split('=')[1];
              var isHave = false;
              for (var i = 0; i < this.flowParam.length; i++) {
                if (this.flowParam[i].key === paramf.key) {
                  this.flowParam[i].value = paramf.value;
                  isHave = true;
                }
              }
              if (!isHave) {
                this.flowParam.push(paramf);
              }
            }
          } else {
            var paramf = {};
            paramf.key = params.split('=')[0];
            paramf.value = params.split('=')[1];
            var isHave = false;
            for (var i = 0; i < this.flowParam.length; i++) {
              if (this.flowParam[i].key === paramf.key) {
                this.flowParam[i].value = paramf.value;
                isHave = true;
              }
            }
            if (!isHave) {
              this.flowParam.push(paramf);
            }
          }
        },
        submitFn: function (opType) { // 功能方法实现接口
          var _this = this;
          _this.commentInfo.commentSign = opType;
          _this.$refs.commentForm.validate(function (vaild) { // 校验规则
            if (vaild) {
              _this.submitbefore();
              if (opType == 'O-6') { // 转办
                _this.title = 'change';
                _this.getChangeUser();
              } else if (opType == 'O-7') { // 协办
                _this.title = 'assist';
                _this.getAssistUser();
              } else if (opType == 'O-8') { // 否决
                _this.refuse();
              } else if (opType == 'O-9') { // 跳转
                _this.title = 'jump';
                _this.JumpDialogOpen();
                _this.jumpNodeSelect.showDialog = true;
              } else if (opType == 'O-12') { // 同意提交
                _this.agreeNodeSelect.showDialog = true;
              }
            } else {
              _this.$message({ duration: 6000,
                message: '请检查输入项是否合法!',
                type: 'warning'
              });
            }
          });
        },
        cancel: function () { // 跳转到之前的页面
          yufp.router.to(this.returnBackFuncId, null, this.returnBackRootId);
        },
        saveComment: function () { // 保存评论
          var _this = this;
          this.$refs['commentForm'].validate(function (valid) {
            if (valid) {
              var data = _this.instanceIdInfo;
              yufp.extend(true, data, _this.commentInfo);
              // data.commentSign = 'O-12';
              data.commentSign = '';
              yufp.service.request({
                method: 'POST',
                data: data,
                url: _this.urls.saveComment,
                callback: function (code, message, response) {
                  if (response.code == 0) {
                    if (response.data != null) {
                      _this.$message({ message: '保存成功', type: 'success', duration: 6000 });
                      _this.$refs['commentForm'].resetFields(); // 重置表单
                      _this.commentInfo = response.data;
                    } else {
                      _this.$message({ duration: 6000,
                        message: '保存意见失败',
                        type: 'error'
                      });
                    }
                  } else {
                    _this.$message({ duration: 6000,
                      message: '保存异常:' + response.message,
                      type: 'error'
                    });
                  }
                }
              });
            } else {
              _this.$message({ duration: 6000,
                message: '请检查输入项是否合法!',
                type: 'warning'
              });
            }
          });
        },
        signIn: function () { // 签收
          var _this = this;
          _this.instanceIdInfo.userId = _this.currentUserId;
          yufp.service.request({
            method: 'GET',
            data: _this.instanceIdInfo,
            url: _this.urls.signIn,
            callback: function (code, message, response) {
              if (response.code == 0) {
                _this.$message({ duration: 6000, message: response.data.tip, type: 'success' });
                yufp.router.to(_this.returnBackFuncId, null, _this.returnBackRootId);
              } else {
                _this.$message({ duration: 6000,
                  message: '签收异常:' + response.message,
                  type: 'error'
                });
              }
            }
          });
        },
        unSignIn: function () {
          var _this = this;
          _this.instanceIdInfo.userId = _this.currentUserId;
          yufp.service.request({
            method: 'GET',
            data: _this.instanceIdInfo,
            url: _this.urls.unSignIn,
            callback: function (code, message, response) {
              if (response.code == 0) { // 跳转到之前的页面
                _this.$message(response.data.tip);
                yufp.router.to(_this.returnBackFuncId, null, _this.returnBackRootId);
              } else {
                _this.$message({ duration: 6000,
                  message: '撤销签收异常:' + response.message,
                  type: 'error'
                });
              }
            }
          });
        },
        refuse: function () { // 否决
          var _this = this;
          _this.$refs.commentForm.validate(function (valid) {
            if (valid) {
              _this.$confirm('确定否决此流程？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(function () {
                var param = {};
                param.orgId = _this.currentOrgId;
                _this.commentInfo.commentSign = 'O-8';
                param.comment = _this.commentInfo;
                yufp.service.request({
                  method: 'POST',
                  data: param,
                  url: _this.urls.refuse,
                  callback: function (code, message, response) {
                    if (response.code == 0) { // 跳转到之前的页面
                      _this.$message(response.data.tip + ';');
                      yufp.router.to(_this.returnBackFuncId, null, _this.returnBackRootId);
                    } else {
                      _this.$message({ duration: 6000,
                        message: '否决异常:' + response.message,
                        type: 'error'
                      });
                    }
                  }
                });
              }).catch(function () {
                _this.$message({ duration: 6000,
                  type: 'info',
                  message: '已取消'
                });
              });
            } else {
              _this.$message({ duration: 6000,
                message: '请检查输入项是否合法!',
                type: 'warning'
              });
            }
          });
        },
        changeFn: function (userId) { // 转办
          var _this = this;
          var param = {};
          param.orgId = _this.currentOrgId;
          _this.commentInfo.commentSign = 'O-6';
          if (_this.commentInfo.userComment == '') {
            _this.commentInfo.userComment = '[转办]';
          }
          param.comment = _this.commentInfo;
          param.changeUserId = userId;
          yufp.service.request({
            method: 'POST',
            data: param,
            url: _this.urls.change,
            callback: function (code, message, response) {
              if (response.code == 0) { // 跳转到之前的页面
                _this.$message(response.data.tip + ';');
                yufp.router.to(_this.returnBackFuncId, null, _this.returnBackRootId);
              } else {
                _this.$message({ duration: 6000,
                  message: '转办提交异常:' + response.message,
                  type: 'error'
                });
              }
            }
          });
        },
        getChangeUser: function () { // 获取转办可选的办理人员
          var _this = this;
          var param = {
            orgId: _this.currentOrgId,
            instanceId: _this.instanceIdInfo.instanceId,
            nodeId: _this.instanceIdInfo.nodeId,
            userId: _this.currentUserId
          };
          yufp.service.request({
            method: 'POST',
            data: param,
            url: _this.urls.getchangeUser,
            callback: function (code, message, response) {
              if (response.code == 0) {
                if (response.data != null) { // 跳转到之前的页面
                  _this.UserSelect.Users = response.data;
                  _this.UserSelect.showUserDialog = true;
                } else {
                  _this.$message({ duration: 6000,
                    message: '未获取到可转办人员',
                    type: 'warning'
                  });
                }
              } else {
                _this.$message({ duration: 6000,
                  message: '获取转办人员异常:' + response.message,
                  type: 'error'
                });
              }
            }
          });
        },
        assistFn: function (userId) { // 协办
          var _this = this;
          var param = {};
          param.orgId = _this.currentOrgId;
          _this.commentInfo.commentSign = 'O-7';
          if (_this.commentInfo.userComment == '') {
            _this.commentInfo.userComment = '[协助办理]';
          }
          param.comment = _this.commentInfo;
          param.assistUserId = userId;
          yufp.service.request({
            method: 'POST',
            data: param,
            url: _this.urls.assist,
            callback: function (code, message, response) {
              if (response.code == 0) { // 跳转到之前的页面
                _this.$message(response.data.tip + ';');
                yufp.router.to(_this.returnBackFuncId, null, _this.returnBackRootId);
              } else {
                _this.$message({ duration: 6000,
                  message: '协办提交异常:' + response.message,
                  type: 'error'
                });
              }
            }
          });
        },
        getAssistUser: function () { // 获取协办可选的办理人员
          var _this = this;
          var param = {
            orgId: _this.currentOrgId,
            instanceId: _this.instanceIdInfo.instanceId,
            nodeId: _this.instanceIdInfo.nodeId,
            userId: _this.currentUserId
          };
          yufp.service.request({
            method: 'POST',
            data: param,
            url: _this.urls.getassistUser,
            callback: function (code, message, response) {
              if (response.code == 0) {
                if (response.data != null) { // 跳转到之前的页面
                  _this.UserSelect.Users = response.data;
                  _this.UserSelect.showUserDialog = true;
                } else {
                  _this.$message({ duration: 6000,
                    message: '未获取到可协助办理人员',
                    type: 'warning'
                  });
                }
              } else {
                _this.$message({ duration: 6000,
                  message: '获取协助办理人员异常:' + response.message,
                  type: 'error'
                });
              }
            }
          });
        },
        agreeFn: function () { // 节点提交
          // 遍历选中节点
		  yufp.router.sendMessage(this.bizPage, '01', this.flowParam);
          var nodes = [];
          if (this.agreeRadio != '') {
            nodes.push(this.agreeRadio);
          }

          if (this.agreeCheckBox.length > 0) {
            for (var i = 0; i < this.agreeCheckBox.length; i++) {
              nodes.push(this.agreeCheckBox[i]);
            }
          }
          // 处理选中的下一节点相关信息
          var nodeInfos = [];
          for (var i = 0; i < nodes.length; i++) {
            for (var j = 0; j < this.agreeNextNodes.length; j++) {
              if (this.agreeNextNodes[j].nodeId == nodes[i]) {
                var nodeInfo = {};
                nodeInfo.nextNodeId = nodes[i];
                var nextUser = [];
                var nextCopyUser = [];
                if (this.agreeNextNodes[j].userInfos != null && this.agreeNextNodes[j].userInfos != undefined) {
                  for (var k = 0; k < this.agreeNextNodes[j].userInfos.length; k++) { // 去重
                    nextUser.push(this.agreeNextNodes[j].userInfos[k].userId);
                  }
                }
                if (this.agreeNextNodes[j].copyUserInfos != null && this.agreeNextNodes[j].copyUserInfos != undefined) {
                  for (var l = 0; l < this.agreeNextNodes[j].copyUserInfos.length; l++) { // 去重
                    nextCopyUser.push(this.agreeNextNodes[j].copyUserInfos[l].userId);
                  }
                }
                nodeInfo.nextNodeUserIds = nextUser;
                nodeInfo.nextNodeCopyUserIds = nextCopyUser;
                nodeInfos.push(nodeInfo);
              }
            }
          }
          // 校验节点选择的处理人
          var _this = this;
          if (nodeInfos.length == 0) {
            _this.$message({ duration: 6000,
              message: '选择节点'
            });
            return;
          } else {
            for (var i = 0; i < nodeInfos.length; i++) {
              if (nodeInfos[i].nextNodeUserIds.length == 0) {
                _this.$message({ duration: 6000,
                  message: '选择节点处理人'
                });
                return;
              }
            }
          }
          var param = {};
          if (_this.agreeIsLastRadio == 'Y') { // 是否直接提交， 一般【办理类型】是[多人顺序可结束]或[多人并行可结束]时生效，可以选择true和false;
            param.lastOne = true;
          }
          param.orgId = _this.currentOrgId;
          param.nextNodeInfos = nodeInfos;
          // 流程评论提交
          if (_this.commentInfo.userComment == '') {
            _this.commentInfo.userComment = '[同意]';
            _this.commentInfo.commentSign = 'O-12';
          }
          param.comment = _this.commentInfo;
          var paramWF = {};
          for (var i = 0; i < _this.flowParam.length; i++) { // 流程参数提交
            paramWF[_this.flowParam[i].key] = _this.flowParam[i].value;
          }
		  console.log(paramWF);
          param.param = paramWF;
          yufp.service.request({
            method: 'POST',
            data: param,
            url: _this.urls.submit,
            callback: function (code, message, response) {
              if (response.code == 0) { // 跳转到之前的页面
                for (var i = 0; i < response.data.length; i++) {
                  if (response.data[i].code === 'E') {
                    // 正常结束
                    _this.$message(response.data[i].tip);
                  } else {
                    _this.$message(response.data[i].tip + ';' + response.data[i].nodeName + '@' + response.data[i].userNames);
                  }
                }
                yufp.router.to(_this.returnBackFuncId, null, _this.returnBackRootId);
              } else {
                _this.$message({ duration: 6000, message: '提交异常:' + response.message.substring(0, 80), type: 'error' });
                if (response.message != null) {

                } else {
                  _this.$message({ duration: 6000,
                    message: '提交异常!',
                    type: 'error'
                  });
                }
              }
            }
          });
        },
        agreeDialogOpen: function () { // 提交窗口打开事件
          var _this = this;
          yufp.service.request({
            method: 'GET',
            data: _this.instanceIdInfo,
            url: _this.agreeNodeSelect.nodeUrl,
            callback: function (code, message, response) {
              if (response.code == 0) { // 跳转到之前的页面
                if (response.data != null) {
                  _this.agreeNextNodes = response.data;
                  var data = response.data;
                  _this.agreeUserCheck(data);
                  if (_this.instanceIdInfo.nodeType == '0' || _this.instanceIdInfo.nodeType == '1' || _this.instanceIdInfo
                    .nodeType == '3') {
                    _this.agreeShowRadio = true;
                  } else { // 非单选节点
                    _this.agreeShowRadio = false;
                  }
                } else {
                  _this.$message({ duration: 6000,
                    message: '未获取到下一提交节点信息!',
                    type: 'warning'
                  });
                }
              } else {
                _this.$message({ duration: 6000,
                  message: '获取下一节点信息异常:' + response.message,
                  type: 'error'
                });
              }
            }
          });
        },
        agreeUserCheck: function (data) { // 判断节点是否是系统指定,并对其进行处理
          var _this = this;
          for (var i = 0; i < data.length; i++) {
            var users = data[i].users;
            if (_this.agreeNextNodes[i].isSysUser == undefined) {
              _this.$set(_this.agreeNextNodes[i], 'isSysUser', '');
            }
            if (_this.agreeNextNodes[i].selected == undefined) {
              _this.$set(_this.agreeNextNodes[i], 'selected', '');
            }
            for (var j = 0; j < users.length; j++) {
              if (users[j].userId == 'system_user') {
                _this.agreeNextNodes[i].isSysUser = true;
                _this.agreeNextNodes[i].selected = false;
                var user = {
                  userId: users[j].userId,
                  userName: users[j].userName
                };
                if (_this.agreeNextNodes[i].userInfos == undefined) {
                  _this.$set(_this.agreeNextNodes[i], 'userInfos', []);
                }
                _this.agreeNextNodes[i].userInfos.push(user);
              }
            }
          }
        },
        agreeRadioChange: function (val) { // 节点选择变化事件
          var _this = this;
          var nodeIds = [];
          var checked = false;
          if (_this.agreeShowRadio) {
            nodeIds.push(val);
          } else {
            nodeIds = val;
          }
          // 未被选择的节点处理
          for (var i = 0; i < _this.agreeNextNodes.length; i++) {
            checked = false;
            for (var k = 0; k < nodeIds.length; k++) {
              if (nodeIds[k] == _this.agreeNextNodes[i].nodeId) {
                checked = true;
              }
            }
            if (!checked) {
              _this.agreeNextNodes[i].userSelected = '';
              _this.agreeNextNodes[i].selected = false;
            }
          }
          // 对选择的数据项进行处理
          for (var k = 0; k < nodeIds.length; k++) {
            var nodeId = nodeIds[k];
            for (var i = 0; i < _this.agreeNextNodes.length; i++) {
              if (nodeId == _this.agreeNextNodes[i].nodeId) {
                _this.agreeNextNodes[i].selected = true;
                if (_this.agreeNextNodes[i].userInfos == undefined) {
                  _this.$set(_this.agreeNextNodes[i], 'userInfos', []);
                }
                var userInfosT = _this.agreeNextNodes[i].userInfos;
                var userName = '';
                for (var j = 0; j < userInfosT.length; j++) {
                  userName = userName + userInfosT[j].userName + ';';
                }
                _this.agreeNextNodes[i].userSelected = userName;
              }
            }
          }
        },
        agreeSelectNodeUser: function (node, index) { // 选择按钮
          this.agreeIndex = index;
          this.agreeUserDialogOpen(node.nodeId);
        },
        agreeUserDialogOpen: function (nodeId) { // 选择节点办理人员窗口打开事件处理
          var _this = this;
          var nodeInfo = {};
          nodeInfo.instanceId = _this.instanceIdInfo.instanceId;
          nodeInfo.nodeId = nodeId;
          var param = {
            condition: JSON.stringify(nodeInfo)
          };
          yufp.service.request({
            method: 'GET',
            data: param,
            url: _this.agreeNodeSelect.userUrl,
            callback: function (code, message, response) {
              if (response.code == 0) {
                if (response.data != null) {
                  _this.agreeNodeSelect.userTableData = response.data;
                  _this.agreeNodeSelect.showUserDialog = true;
                } else {
                  _this.$message({ duration: 6000,
                    message: '未获取到办理人员信息!',
                    type: 'warning'
                  });
                }
              } else {
                _this.$message({ duration: 6000,
                  message: '获取办理人员异常:' + response.message,
                  type: 'warning'
                });
              }
            }
          });
        },
        agreeRowDbClick: function (row, event) { // tag双击事件
          var user = {};
          user.userId = row.userId;
          user.userName = row.userName;
          if (this.agreeNextNodes[this.agreeIndex].userInfos == undefined) {
            this.$set(this.agreeNextNodes[this.agreeIndex], 'userInfos', []);
          }
          var userInfosT = this.agreeNextNodes[this.agreeIndex].userInfos;
          for (var i = 0; i < userInfosT.length; i++) { // 去重
            if (userInfosT[i].userId == user.userId) {
              return;
            }
          }
          userInfosT.push(user);
        },
        agreeTagClose: function (tag) { // tag关闭事件
          if (this.agreeNextNodes[this.agreeIndex].userInfos == undefined) {
            this.$set(this.agreeNextNodes[this.agreeIndex], 'userInfos', []);
          }
          var userInfosT = this.agreeNextNodes[this.agreeIndex].userInfos;
          userInfosT.splice(userInfosT.indexOf(tag), 1);
        },
        agreeUserClose: function () { // 选取返回
          this.agreeNodeSelect.showUserDialog = false;
          var userName = '';
          if (this.agreeNextNodes[this.agreeIndex].userInfos == undefined) {
            this.$set(this.agreeNextNodes[this.agreeIndex], 'userInfos', []);
          }
          var userInfosT = this.agreeNextNodes[this.agreeIndex].userInfos;
          for (var i = 0; i < userInfosT.length; i++) {
            userName = userName + userInfosT[i].userName + ';';
          }
          this.agreeNextNodes[this.agreeIndex].userSelected = userName;
        },
        agreeDialogClose: function () { // 提交窗口关闭事件
          this.agreeRadio = '';
          this.agreeCheckBox = [];
		  this.agreeIsLastRadio = 'N';
        },
        returnBackFn: function () { // 退回操作
          var _this = this;
          var param = {};
          _this.$refs.commentForm.validate(function (vaild) { // 校验规则
            if (vaild) {
              param.orgId = _this.currentOrgId;
              _this.commentInfo.commentSign = 'O-2';
              if (_this.commentInfo.userComment == '') {
                _this.commentInfo.userComment = '[退回]';
              }
              param.comment = _this.commentInfo;
              _this.$confirm('是否执行退回操作?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(function () {
                yufp.service.request({
                  method: 'POST',
                  data: param,
                  url: _this.urls.returnBack,
                  callback: function (code, message, response) {
                    if (response.code == 0) { // 跳转到之前的页面
                      _this.$message(response.data.tip + ';' + response.data.nodeName + '@' + response.data.userNames);
                      yufp.router.to(_this.returnBackFuncId, null, _this.returnBackRootId);
                    } else {
                      _this.$message({ duration: 6000,
                        message: '退回异常:' + response.message,
                        type: 'error'
                      });
                    }
                  }
                });
              }).catch(function () {
                _this.$message({ duration: 6000,
                  type: 'info',
                  message: '已取消'
                });
              });
            } else {
              _this.$message({ duration: 6000,
                message: '请检查输入项是否合法!',
                type: 'warning'
              });
            }
          });
        },
        callBackFn: function () { // 打回操作
          var _this = this;
          _this.$refs.commentForm.validate(function (vaild) { // 校验规则
            if (vaild) {
              _this.backNodeModel = '';
              _this.callbackNodeSelect.showDialog = true;
            } else {
              _this.$message({ duration: 6000,
                message: '请检查输入项是否合法!',
                type: 'warning'
              });
            }
          });
        },
        backDialogOpen: function () { // 获取可打回节点的信息
          var _this = this;
          var param = {
            orgId: _this.instanceIdInfo.orgId,
            instanceId: _this.instanceIdInfo.instanceId,
            nodeId: _this.instanceIdInfo.nodeId,
            userId: _this.currentUserId
          };
          yufp.service.request({
            method: 'POST',
            data: param,
            url: _this.callbackNodeSelect.nodeUrl,
            callback: function (code, message, response) {
              if (response.code == 0) {
                if (response.data != null) {
                  var nodes = response.data;
                  for (var i = 0; i < nodes.length; i++) {
                    var node = {
                      nodeId: nodes[i].nodeId,
                      nodeName: nodes[i].nodeName,
                      selected: false,
                      usersList: []
                    };
                    var users = nodes[i].users;
                    if (users.length != 0) {
                      for (var k = 0; k < users.length; k++) {
                        var user = {
                          userId: users[k].userId,
                          userName: users[k].userName
                        };
                        node.usersList.push(user);
                      }
                    }
                    _this.backNodes.push(node);
                  }
                } else {
                  _this.$message({ duration: 6000,
                    message: '未获取到可打回节点!',
                    type: 'warning'
                  });
                }
              } else {
                _this.$message({ duration: 6000,
                  message: '获取打回节点异常:' + response.message,
                  type: 'error'
                });
              }
            }
          });
        },
        radioChange: function (val) { // 打回节点选择
          this.userModel = '';
          for (var i = 0; i < this.backNodes.length; i++) {
            var id = this.backNodes[i].nodeId;
            this.backNodes[i].selected = false;
            if (id == val) {
              this.backNodes[i].selected = true;
            }
          }
        },
        wfCallBackClose: function () { // 打回界面关闭
          var _this = this;
          _this.backActiveName = 'first';
          _this.backnode = 1;
          _this.backNodes = [];
          // _this.usersList = [];
          _this.callbackNodeSelect.showDialog = false;
        },
        wfCallBack: function () { // 打回接口调用
          var _this = this;
		  if (!_this.backNodeModel) {
			  _this.$message({ duration: 6000,
			    message: '请选择打回节点!',
			    type: 'error'
			  });
			  return false;
		  }
		  if (!_this.userModel) {
		  	  _this.$message({ duration: 6000,
		  	    message: '请选择打回节点的办理人!',
		  	    type: 'error'
		  	  });
		  	  return false;
		  }
          _this.callbackNodeSelect.showDialog = false;
          var param = {
            callbackNodeId: _this.backNodeModel,
            callbackUserId: _this.userModel,
            callbackModel: _this.backnode + '', // 打回模式 【 0-打回后提交直接给我，1-打回后提交沿流程路径（默认）】
            orgId: _this.currentOrgId
          };
          _this.commentInfo.commentSign = 'O-1';
          if (_this.commentInfo.userComment == '') {
            _this.commentInfo.userComment = '[打回]';
          }
          param.comment = _this.commentInfo;
          // 打回接口调用
          yufp.service.request({
            method: 'POST',
            data: param,
            url: _this.urls.callBack,
            callback: function (code, message, response) {
              if (response.code == 0) { // 跳转到之前的页面
                _this.$message({ duration: 6000,
                  message: response.data.tip,
                  type: 'success'
                });
                yufp.router.to(_this.returnBackFuncId, null, _this.returnBackRootId);
              } else {
                _this.$message({ duration: 6000,
                  message: '打回异常:' + response.message,
                  type: 'error'
                });
              }
            }
          });
          _this.wfCallBackClose();
        },
        // 跳转
        JumpDialogOpen: function () { // 获取可跳转节点
          var _this = this;
          var param = {
            orgId: _this.instanceIdInfo.orgId,
            instanceId: _this.instanceIdInfo.instanceId,
            nodeId: _this.instanceIdInfo.nodeId,
            userId: _this.currentUserId
          };
          yufp.service.request({
            method: 'POST',
            data: param,
            url: _this.jumpNodeSelect.nodeUrl,
            callback: function (code, message, response) {
              if (response.code == 0) {
                if (response.data != null) { // 跳转到之前的页面
                  var nodes = response.data;
                  for (var i = 0; i < nodes.length; i++) {
                    var n = {
                      nodeId: nodes[i].nodeId,
                      nodeName: nodes[i].nodeName,
                      selected: false,
                      selectUser: [],
                      usersList: nodes[i].users
                    };
                    _this.jumpNodes.push(n);
                  }
                } else {
                  _this.$message({ duration: 6000,
                    message: '未获取到可跳转节点!',
                    type: 'warning'
                  });
                }
              } else {
                _this.$message({ duration: 6000,
                  message: '获取跳转节点异常:' + response.message,
                  type: 'error'
                });
              }
            }
          });
        },
        jumpSelectUser: function (node, index) { // 获取选择的节点的人员
          var _this = this;
          _this.index = index;
          if (node.usersList.length == 1) {
            _this.$nextTick(function () {
              _this.jumpNodes[index].selectUser = node.usersList[0];
            });
          } else {
            _this.UserSelect.Users = node.usersList;
            _this.UserSelect.showUserDialog = true;
          }
        },
        jumpradioChange: function (val) { // 跳转节点选择
          for (var i = 0; i < this.jumpNodes.length; i++) {
            this.jumpNodes[i].selected = false;
            var id = this.jumpNodes[i].nodeId;
            if (id == val) {
              this.jumpNodes[i].selected = true;
            }
            this.jumpNodes[i].selectUser = [];
          }
          this.UserSelect.SelectUsers = [];
        },
        jumpFn: function () { // 跳转接口调用
          var _this = this;
          var param = {
            jumpNodeId: _this.jumpNodeModel,
            jumpUserId: _this.jumpNodes[_this.index].selectUser.userId,
            orgId: _this.instanceIdInfo.orgId
          };
          _this.commentInfo.commentSign = 'O-9';
          if (_this.commentInfo.userComment == '') {
            _this.commentInfo.userComment = '[跳转]';
          }
          param.comment = _this.commentInfo;
          yufp.service.request({
            method: 'POST',
            data: param,
            url: _this.urls.jump,
            callback: function (code, message, response) {
              if (response.code == 0) { // 跳转到之前的页面
                _this.$message({ duration: 6000,
                  message: response.data.tip + ';',
                  type: 'success'
                });
                yufp.router.to(_this.returnBackFuncId, null, _this.returnBackRootId);
              } else {
                _this.$message({ duration: 6000,
                  message: '跳转异常:' + response.message,
                  type: 'error'
                });
              }
            }
          });
          _this.jumpClose();
        },
        jumpClose: function () { // 跳转窗口 关闭
          this.jumpNodes = [];
          this.jumpNodeModel = '';
          this.jumpNodeSelect.showDialog = false;
        },

        // 人员选择弹框
        submitbefore: function () { // 弹框前处理
          this.UserSelect.Users = [];
          this.UserSelect.SelectUsers = [];
        },
        RowDbClick: function (row, event) { // 列表双击事件
          var user = {
            userId: row.userId,
            userName: row.userName
          };
          if (this.UserSelect.SelectUsers == undefined) {
            this.$set(this.UserSelect, 'SelectUsers', []);
          }
          var userInfosT = this.UserSelect.SelectUsers;
          for (var i = 0; i < userInfosT.length; i++) { // 去重
            if (userInfosT[i].userId == row.userId) {
              return;
            }
          }
          userInfosT.push(user);
        },
        TagClose: function (tag) { // tag页签关闭事件
          if (this.UserSelect.SelectUsers == undefined) {
            this.$set(this.UserSelect, 'SelectUsers', []);
          }
          var userInfosT = this.UserSelect.SelectUsers;
          userInfosT.splice(userInfosT.indexOf(tag), 1);
        },
        UserDialogClose: function () { // 弹框关闭
          this.UserSelect.showUserDialog = false;

          if (this.UserSelect.SelectUsers == undefined) {
            this.$set(this.UserSelect, 'SelectUsers', []);
          }
		  var userInfosT = this.UserSelect.SelectUsers;
          if (this.title == 'jump' || this.title == 'assist' || this.title == 'change') {
            if (userInfosT.length > 1) {
              this.$message({
                message: '该功能只能选择一个办理人员!',
                type: 'warning',
                duration: 6000
              });
              return false;
            }
          }
          var userName = userInfosT[0].userName;
          var userId = userInfosT[0].userId;
          if (this.title == 'jump') {
            this.jumpNodes[this.index].selectUser.userName = userName;
            this.jumpNodes[this.index].selectUser.userId = userId;
          } else if (this.title == 'assist') {
            this.assistFn(userId);
          } else if (this.title == 'change') {
            this.changeFn(userId);
          } else if (this.title == 'copy') {
            for (var i = 0; i < userInfosT.length; i++) {
              userName = '';
              userName = userName + userInfosT[i].userName + ';';
            }
            this.agreeNextNodes[this.agreeIndex].copyUser = userName;
            this.agreeNextNodes[this.agreeIndex].copyUserInfos = userInfosT;
          }
        },
        wfGatherFn: function () { // 会办功能实现
          var _this = this;
          var param = {
            instanceId: _this.instanceIdInfo.instanceId,
            userId: _this.currentUserId,
            nodeId: _this.instanceIdInfo.nodeId
          };
          this.$confirm('确定要发起会办吗？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(function () {
            yufp.service.request({
              method: 'GET',
              data: param,
              url: backend.workflowService + '/api/metting/start',
              callback: function (code, message, response) {
                if (response.data == true) {
                  _this.$message({ duration: 6000,
                    message: '发起会办成功!',
                    type: 'success'
                  });
                } else {
                  _this.$message({ duration: 6000,
                    message: '该流程已经进行过会办!',
                    type: 'warning'
                  });
                }
                yufp.router.to(_this.returnBackFuncId, null, _this.returnBackRootId);
              }
            });
          }).catch(function () {
            _this.$message({ duration: 6000,
              type: 'info',
              message: '已取消'
            });
          });
        },
        Select: function () {
          this.agreeNodeSelect.showUserDialog = true;
        },
        currpageChange: function (val) {
          this.currpage = val;
        },
        pagesizeChange: function (val) {
          this.pagesize = val;
        },
        unSignInTaskPool: function () { // 放回项目池
          var _this = this;
          var param = {
            instanceId: _this.instanceIdInfo.instanceId,
            nodeId: _this.instanceIdInfo.nodeId,
            userId: yufp.session.userCode,
            poolId: _this.button.taskPoolId
          };
          _this.$confirm('确定要放回项目池吗？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(function () {
            yufp.service.request({
              method: 'POST',
              data: param,
              url: _this.urls.unSignInTaskPool,
              callback: function (code, message, response) {
                if (response.code == 0) {
                  _this.$message({ duration: 6000,
                    message: response.data.tip,
                    type: 'success'
                  });
                } else {
                  _this.$message({ duration: 6000,
                    message: '放回项目池异常:' + response.message,
                    type: 'warning'
                  });
                }
                yufp.router.to(_this.returnBackFuncId, null, _this.returnBackRootId);
              }
            });
          }).catch(function () {
            _this.$message({ duration: 6000,
              type: 'info',
              message: '已取消'
            });
          });
        },
        subFlowStart: function () { // 发起子流程功能
          var _this = this;
          _this.$refs.commentForm.validate(function (vaild) { // 校验规则
            if (vaild) {
              _this.$confirm('是否执行发起子流程操作?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(function () {
                var param = {};
                param.orgId = _this.currentOrgId;
                param.systemId = 'cmis';
                param.bizType = _this.button.subFlowId;
                _this.commentInfo.commentSign = '';
                if (_this.commentInfo.userComment == '') {
                  _this.commentInfo.userComment = '[发起子流程]';
                }
                param.comment = _this.commentInfo;
                yufp.service.request({
                  method: 'POST',
                  data: param,
                  url: _this.urls.subFlowStart,
                  callback: function (code, message, response) {
                    if (response.code == 0) { // 跳转到之前的页面
                      _this.$message(response.data.tip + ';');
                      yufp.router.to(_this.returnBackFuncId, null, _this.returnBackRootId);
                    } else {
                      _this.$message({ duration: 6000, message: '子流程发起异常:' + response.message + ';', type: 'error' });
                    }
                  }
                });
              }).catch(function () {
                _this.$message({ duration: 6000,
                  type: 'info',
                  message: '已取消'
                });
              });
            } else {
              _this.$message({ duration: 6000,
                message: '请检查输入项是否合法!',
                type: 'warning'
              });
            }
          });
        },
        agreeSelectCopyUser: function (node, index) {
          var _this = this;
          _this.agreeIndex = index;
          if (_this.agreeNextNodes[_this.agreeIndex].copyUserInfos == undefined) {
            _this.$set(_this.agreeNextNodes[_this.agreeIndex], 'copyUserInfos', []);
          }
          if (_this.agreeNextNodes[_this.agreeIndex].copyUser == undefined) {
            _this.$set(_this.agreeNextNodes[_this.agreeIndex], 'copyUser', '');
          }
          var param = {
            orgId: _this.currentOrgId,
            instanceId: _this.instanceIdInfo.instanceId,
            nodeId: _this.instanceIdInfo.nodeId,
            copyNodeId: node.nodeId
          };
          yufp.service.request({
            method: 'POST',
            data: param,
            url: _this.urls.getCopyUser,
            callback: function (code, message, response) {
              if (response.code == 0) { // 跳转到之前的页面
                if (response.data != null) {
                  _this.UserSelect.Users = response.data;
                  _this.title = 'copy';
                  _this.UserSelect.showUserDialog = true;
                } else {
                  _this.$message({ duration: 6000,
                    message: '没有抄送人员可以选择!',
                    type: 'warning'
                  });
                }
              } else {
                if (response.message != null) {
                  _this.$message({ duration: 6000,
                    message: response.message,
                    type: 'warning'
                  });
                } else {
                  _this.$message({ duration: 6000,
                    message: '获取可抄送人员异常:' + response.message,
                    type: 'warning'
                  });
                }
              }
            }
          });
        }
      }
    });
  };
  exports.onmessage = function (type, message, cite, vm) {
    if (type == '01') {
      vm.flowParam = message;
    }
  };
});
